<?php
/**
 * YCmf.php
 *
 * @author Hua Yang <htmlcook@gmail.com>
 * @since 2.0
 */

Yii::setPathOfAlias('common', dirname(__FILE__));
Yii::import('common.components.*');

/**
 * Class YCmf
 */
class YCmf extends YiiBase
{
	public static function createFrontendApplication($config = null)
	{
		$commonConfig = require Yii::getPathOfAlias('common.config') . '/main.php';
		$config = CMap::mergeArray($commonConfig , is_array($config) ? $config : array());
		$app = self::createApplication('YWebApplication', $config);
		if (defined('INSTALLED') && $app->option->get('site_status') == 0) {
			$app->controllerMap['offline'] = array(
				'class' => 'common.controllers.YOfflineController',
			);

			$app->catchAllRequest = array(
				'offline/notice'
			);
		}
		return $app;
	}

	public static function createBackendApplication($config = null)
	{
		$commonConfig = require Yii::getPathOfAlias('common.config') . '/main.php';
		$backendConfig = require Yii::getPathOfAlias('backend.config') . '/main.php';
		$config = CMap::mergeArray($commonConfig , $backendConfig, is_array($config) ? $config : array());
		/** @var YWebApplication $app */
		$app = self::createApplication('YWebApplication', $config);
		if (!defined('INSTALLED')) {
			$app->setModules(array(
				'install' => array(
					'class' => 'common.install.InstallModule',
				)
			));
			$app->catchAllRequest = array(
				'/install/default'
			);
		}
		return $app;
	}

	/**
	 * CMF 版本
	 *
	 * @return string
	 */
	public static function getVersion()
	{
		return '2.0.0';
	}
} 